package org.jeecg.modules.exZbwjBidEvaluationConfig.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.exZbwjBidEvaluationConfig.domain.entity.ExZbwjBidEvaluationConfig;
import org.jeecg.modules.exZbwjBidEvaluationConfig.domain.form.ExZbwjBidEvaluationConfigForm;
import org.jeecg.modules.exZbwjBidEvaluationConfig.domain.vo.ExZbwjBidEvaluationConfigVO;
import org.jeecg.modules.exZbwjBidEvaluationConfig.service.IExZbwjBidEvaluationConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 开评标配置
 * @Author: jeecg-boot
 * @Date: 2024-10-24
 * @Version: V1.0
 */
@Api(tags = "开评标配置")
@RestController
@RequestMapping("/ExZbwjBidEvaluationConfig/exZbwjBidEvaluationConfig")
@Slf4j
public class ExZbwjBidEvaluationConfigController extends JeecgController<ExZbwjBidEvaluationConfig, IExZbwjBidEvaluationConfigService> {
    @Autowired
    private IExZbwjBidEvaluationConfigService exZbwjBidEvaluationConfigService;

    /**
     * 分页列表查询
     *
     * @param exZbwjBidEvaluationConfig
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "开评标配置-分页列表查询")
    @ApiOperation(value = "开评标配置-分页列表查询", notes = "开评标配置-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ExZbwjBidEvaluationConfig>> queryPageList(ExZbwjBidEvaluationConfig exZbwjBidEvaluationConfig,
                                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                  HttpServletRequest req) {
        QueryWrapper<ExZbwjBidEvaluationConfig> queryWrapper = QueryGenerator.initQueryWrapper(exZbwjBidEvaluationConfig, req.getParameterMap());
        Page<ExZbwjBidEvaluationConfig> page = new Page<ExZbwjBidEvaluationConfig>(pageNo, pageSize);
        IPage<ExZbwjBidEvaluationConfig> pageList = exZbwjBidEvaluationConfigService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    /**
     * 查询项目的开评标设置
     *
     * @param projectId
     * @return
     */
    @ApiOperation(value = "开评标配置-查询项目的开评标设置", notes = "开评标配置-查询项目的开评标设置")
    @GetMapping(value = "/queryByProjectId")
    public Result<List<ExZbwjBidEvaluationConfigVO>> queryByProjectId(@RequestParam(name = "projectId") String projectId) {
        List<ExZbwjBidEvaluationConfigVO> list = exZbwjBidEvaluationConfigService.selectByProjectId(projectId);
        return Result.OK(list);
    }

    /**
     * 查询项目的开评标设置
     *
     * @param sectionId 标段id
     * @return
     */
    @ApiOperation(value = "开评标配置-查询项目的开评标设置详情", notes = "开评标配置-查询项目的开评标设置详情")
    @GetMapping(value = "/queryByProjectIdAndSectionId")
    public Result<ExZbwjBidEvaluationConfigVO> queryBySectionId(@RequestParam(name = "sectionId") String sectionId) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ExZbwjBidEvaluationConfigVO configVO = exZbwjBidEvaluationConfigService.selectByProjectIdAndSectionId(sectionId, sysUser.getId());
        return Result.OK(configVO);
    }

    /**
     * 添加
     *
     * @param exZbwjBidEvaluationConfig
     * @return
     */
    @AutoLog(value = "开评标配置-添加")
    @ApiOperation(value = "开评标配置-添加", notes = "开评标配置-添加")
    //@RequiresPermissions("org.jeecg.modules:ex_zbwj_bid_evaluation_config:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ExZbwjBidEvaluationConfigForm exZbwjBidEvaluationConfig) {
        exZbwjBidEvaluationConfigService.save(exZbwjBidEvaluationConfig);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param exZbwjBidEvaluationConfig
     * @return
     */
    @AutoLog(value = "开评标配置-编辑")
    @ApiOperation(value = "开评标配置-编辑", notes = "开评标配置-编辑")
    //@RequiresPermissions("org.jeecg.modules:ex_zbwj_bid_evaluation_config:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ExZbwjBidEvaluationConfigForm exZbwjBidEvaluationConfig) {
        if (null == exZbwjBidEvaluationConfig.getId()) {
            return Result.error("ID不能为空");
        }
        return exZbwjBidEvaluationConfigService.update(exZbwjBidEvaluationConfig);
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "开评标配置-通过id删除")
    @ApiOperation(value = "开评标配置-通过id删除", notes = "开评标配置-通过id删除")
    //@RequiresPermissions("org.jeecg.modules:ex_zbwj_bid_evaluation_config:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        exZbwjBidEvaluationConfigService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "开评标配置-批量删除")
    @ApiOperation(value = "开评标配置-批量删除", notes = "开评标配置-批量删除")
    //@RequiresPermissions("org.jeecg.modules:ex_zbwj_bid_evaluation_config:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.exZbwjBidEvaluationConfigService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "开评标配置-通过id查询")
    @ApiOperation(value = "开评标配置-通过id查询", notes = "开评标配置-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ExZbwjBidEvaluationConfig> queryById(@RequestParam(name = "id", required = true) String id) {
        ExZbwjBidEvaluationConfig exZbwjBidEvaluationConfig = exZbwjBidEvaluationConfigService.getById(id);
        if (exZbwjBidEvaluationConfig == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(exZbwjBidEvaluationConfig);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param exZbwjBidEvaluationConfig
     */
    //@RequiresPermissions("org.jeecg.modules:ex_zbwj_bid_evaluation_config:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ExZbwjBidEvaluationConfig exZbwjBidEvaluationConfig) {
        return super.exportXls(request, exZbwjBidEvaluationConfig, ExZbwjBidEvaluationConfig.class, "开评标配置");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("ex_zbwj_bid_evaluation_config:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ExZbwjBidEvaluationConfig.class);
    }

}
